const pub = (function () {
    /**
     * 更改窗口时的样式尺寸
     * @param {*} params 
     * @returns 
     */
    const windowReSize = async function (params) {
        let col = params
        let width = document.documentElement.clientWidth;
        if (width < 1000) {
            col = {
                xs: 20,
                offset: 2
            }
        } else {
            col = {
                xs: 8,
                offset: 8
            }
        }
        return col
    }

    /**
     * 无限级分级 树状处理
     * @param {*} list 
     * @returns 
     */
    const getList = async function (list) {
        const treeData = [];
        const map = {};
        
        list.forEach(function (item) {
            map[item.cid] = item;
            // map[item.cid].value = item.cid
        })
        list.forEach(function (item) {
            let parent = map[item.pid];
            if (parent) {
                if(!(parent.children instanceof Array)) {
                    parent.children = new Array();
                }
                parent.children.push(item);
                // (parent.children || (parent.children = [])).push(item);
            } else {
                treeData.push(item);
            }
        })
        return treeData;
    }

    return {
        windowReSize,
        getList
    }
})()

export default pub